﻿using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;

namespace Ajaxna.Designers
{
    public class AddHttpHandlerAction
    {
        // Fields
        private string _path;
        private Type _type;
        private WebConfigAction _webConfigAction;

        // Methods
        public AddHttpHandlerAction(IComponent component, string path, Type type)
        {
            this._path = path;
            this._type = type;
            this._webConfigAction = new WebConfigAction(component);
        }

        public void AddHttpHandler()
        {
            this.WebConfigAction.RemoveHandler(this._path);
            if (this.WebConfigAction.AddHandler(this._path, this._type, "*"))
            {
                this.WebConfigAction.ShowMessage(string.Format("{0} was successfully added to the web.config file", this._path));
            }
        }

        // Properties
        public bool HandlerExists
        {
            get
            {
                return this.WebConfigAction.HandlerExists(this._path, this._type, "*");
            }
        }

        private WebConfigAction WebConfigAction
        {
            get
            {
                return this._webConfigAction;
            }
        }
    }
}
